package et.recipe;

import cpw.mods.fml.common.FMLCommonHandler;
import thaumcraft.common.config.ConfigResearch;

import java.lang.reflect.Field;

/**
 * Created by winston_wang on 2017/6/3.
 */
public class ETRecipeManager {
    public ETRecipeManager(String mods[]){
        initRecipeRegistry(mods);
    }
    private void initRecipeRegistry(String mods[]){
        Class researchClass = ETRecipes.class;
        for(Field field : researchClass.getDeclaredFields()){
            if (field.isAnnotationPresent(ETRecipe.class)){
                ETRecipe etRecipe = field.getAnnotation(ETRecipe.class);
                if(etRecipe.dependMods().length!=0) {
                    if(etRecipe.dependMods().length==mods.length) {
                        int index = 0;
                        for (String modid : etRecipe.dependMods()) {
                            for(String checkid : mods){
                                if (!modid.contains(checkid)) {
                                    continue;
                                }
                            }
                            index++;
                        }
                        try {
                            ConfigResearch.recipes.put(etRecipe.recipeName(),field.get(null));
                        }catch (Exception e){
                            e.printStackTrace();
                            FMLCommonHandler.instance().exitJava(-125,true);
                        }
                    }
                }else {
                    try {
                        ConfigResearch.recipes.put(etRecipe.recipeName(),field.get(null));
                    }catch (Exception e){
                        e.printStackTrace();
                        FMLCommonHandler.instance().exitJava(-125,true);
                    }
                }
            }
        }
    }
}
